<?php

/**
 * @author     bigface.cc
 * @date       2012-7-8 
 * @version    1.0
 */
//后台登录控制器
class clientAction extends Action {

        private $admin_mod;
        private $items_cate_mod;
        private $result;

        function _initialize() {
                $this->admin_mod = D('admin');
                $this->items_cate_mod = D('items_cate');

                $user_name = $_REQUEST['user_name'];
                $password = md5(trim($_REQUEST['password']));
                $this->result = array();

                $this->result['error'] = true;
                $this->result['msg'] = "登录成功!";

                return;
                if ($this->admin_mod->where("user_name='$user_name' and password='$password'")->count() == 0) {
                        $this->result['error'] = 0;
                        $this->result['msg'] = "账户不正确!";
                        exit(json_encode($this->result));
                } else {
                        $this->result['error'] = 1;
                        $this->result['msg'] = "登录成功!";
                }
        }

        function index() {
                $this->result['content'] = array(
                    'items_cate' => $this->items_cate_mod->field('id,name,pid')->select(),
                );
                exit(json_encode($this->result));
        }

        function upload() {
                $items_mod = D("items");

                $data = json_decode(urldecode($_REQUEST['data']));
                foreach ($data as $item) {
                        $data = array(
                            'cid' => 0,
                            'item_key' => "taobao_" . $item->id,
                            'title' => $item->title,
                            'img' => $item->img,
                            'simg' => $item->img,
                            'bimg' => $item->img,
                            'price' => $item->price,
                            'url' => $item->url,
                        );
                        $items_mod->add($data);
                }
                $this->result['error'] = true;
                $this->result['msg'] = "上传成功!";
                exit(json_encode($this->result));
        }

}